<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
		
		<title></title><meta name="vs_showGrid" content="False">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
	<body>
		<h2>Installing UIB</h2>
		<p>UIB need <strong>SYNEDIT</strong> components with Delphi, Kylix and BCB, this 
			package is used&nbsp;by the&nbsp;SQL property editor. <a href="http://prdownloads.sourceforge.net/synedit/synedit-cvs-2004-10-09.zip?download">
				Download</a> and install this package.</p>
		<ul>
			<li>
				Installing UIB with Delphi.
				<ul>
					<li>
						Add the&nbsp;UIB library path&nbsp;in the Delphi Environment Options, ex: "<font color="#000099">C:\UIB\source".</font>
					</li><li>
						Open and <u>compile</u> the runtime package: UIBD<font color="#ff0033">X</font>R.dpk.
					</li><li>
						Open and <u>install </u>the design pakage: UIBD<font color="#ff0033">X</font>D.dpk</li></ul>
			</li><li>
				Installing UIB with BC++ Builder.
				<ul>
					<li>
						Open and <u>compile</u> the runtime package: UIBC<font color="#ff0033">X</font>R.bpk.
					</li><li>
						Design packages are preconfigured to use SYNEDIT in this path: <font color="#000099">
							"$(BCB)\Source\synedit\Source</font>". Change this path&nbsp;if needed.
					</li><li>
						Open and <u>install </u>the design pakage: UIBC<font color="#ff0033">X</font>D.bpk</li></ul>
			</li><li>
				Installing UIB with Kylix.
				<ul>
					<li>
						Install UIBPack_K3.dpk.</li></ul>
			</li><li>
				Installing UIB on Lazarus.
				<ul>
					<li>
					Install the package named "uiblaz.lpk" in the source directory.
					</li><li>
						Finally rebuild Lazarus IDE because lazarus link packages statically (Tool &gt; 
						Build Lazarus).</li></ul>
			</li>
		</ul>
		<h2>Using TUIBQuery&nbsp;</h2>
		<p style="margin-right: 0px;" dir="ltr">There is 3 methods to use this component.</p>
		<ul>
			<li dir="ltr">
				<h3>Open (Allocate statement&nbsp; + Prepare + Execute + Fetch)</h3>
				Typically used for SELECT statements.<br>
				You can't use the QuickScript property with this method.<br>
				<strong>Note</strong> : <em>If you need to open the same query again&nbsp;but with 
					different
					<br>
					parametters&nbsp;don't&nbsp;Close&nbsp;the&nbsp;query and Open the query
					<br>
					again,&nbsp;it will be <u>faster</u> because the query will not be prepared 
					each time.</em>
				<br>
				<pre>  <br>  Query.SQL.Text := <font color="#333399">'SELECT FIRST_NAME, LAST_NAME, SALARY FROM EMPLOYEE WHERE DEPT_NO = :Num'</font>;<br>  Query.Params.ByNameAsInteger[<font color="#333399">'Num'</font>] := 623;<br>  Query.<font color="#ff0066">Open</font>;<br>  <strong>while</strong> <strong>not</strong> Query.EOF <strong>do</strong>
    <strong>with</strong> Query, Fields <strong>do</strong>
    <strong>begin</strong>
      memo.Lines.Add(format(<font color="#333399">'%s %s, Salary: %f'</font>
         ,
        [ByNameAsString[<font color="#333399">'FIRST_NAME'</font>],<br>         ByNameAsString[<font color="#333399">'LAST_NAME'</font>],<br>         ByNameAsCurrency[<font color="#333399">'SALARY'</font>]]));<br>      Next;<br>    <strong>end</strong>;<br>  Query.Close(etmCommit);				<br>				</pre>
			</li>
		</ul>
		<ul>
			<li dir="ltr">
				<h3>Execute (Allocate statement&nbsp; + Pepare + Execute)</h3>
				Typically used for "Data Pump". It is the fastest way to execute the same<br>
				operation many times without having to prepare the query for each operation.<br>
				You can't use the QuickScript property with this method.
				<pre><strong>const</strong>
  Datas : <strong>array</strong>[1..10] <strong>of</strong> TARecord = (<br>    (COUNTRY: 'blabla0'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla1'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla2'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla3'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla4'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla5'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla6'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla7'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla8'; CURRENCY: 'blabla'),<br>    (COUNTRY: 'blabla9'; CURRENCY: 'blabla'));<br><strong>begin</strong>
  <strong>for</strong> i := 1 <strong>to</strong> 10 <strong>do</strong>
  <strong>begin</strong>
    Query.Params.AsString[0] := Datas[i].COUNTRY;
    Query.Params.AsString[1] := Datas[i].CURRENCY;
    Query.<font color="#ff0066">Execute</font>;<br><font color="#333399">    // for better performance commit every 1000    records <br>// if i mod 1000 = 0 then Transaction.Commit;</font>
  <strong>end</strong>;<br>  Query.Close(etmRollback); <font color="#333399">// change to etmCommit to apply.</font>
        
<strong>end</strong>;<br></pre>
			</li>
		</ul>
		<ul>
			<li dir="ltr">
				<h3 style="margin-right: 0px;">ExecSQL (Execute Immediate)</h3>
				The fastest way to execute many differents SQL statements like a script.<br>
				Setting the QuickScript property to True you must have <u>one SQL statement</u>
				<br>
				<u>per line</u>. This method can use parammetters but can't return results.
				<pre>  Query.QuickScript := True;<br>  Query.SQL.Add(<font color="#333399">'INSERT INTO COUNTRY (COUNTRY,CURRENCY) VALUES (''Test0'',''FFranc'')'</font>);<br>  Query.SQL.Add(<font color="#333399">'DELETE FROM COUNTRY WHERE COUNTRY = ''Test0'''</font>);<br>  .../...<br>  Query.<font color="#ff3366">ExecSQL</font>;<br>  Query.Close(etmCommit);<br>  </pre>
			</li>
		</ul>
		<h2 align="left">Transaction Rules</h2>
		<blockquote style="margin-right: 0px;" dir="ltr">
			<h3>Definitions:</h3>
			<ul>
				<li>
					<u>Commit</u>:<em> apply changes and close transaction.</em>
				</li><li>
					<u>Rollback</u>: <em>cancel changes and close transaction</em>.
				</li><li>
					<u>CommitRetaining</u>:&nbsp;<em>apply changes&nbsp;and keep the transaction open</em>.
				</li><li>
					<u>RollbackRetaining</u>: <em>cancel changes and keep transaction open.</em></li></ul>
			<h3>Rules</h3>
			<ol>
				<li>
				Transactions are&nbsp;started automaticaly when a Query is Open.
				</li><li>
				Transactions stay alive until all attached queries&nbsp;are closed if 
				AutoRetain = True.
				</li><li>
				Transaction rollbacked automatically on internal error (open, ExecSQL, next 
				...).
				</li><li>
					Transaction commited automatically if a query component is destroyed or 
					detached from transaction.</li></ol>
			<h3>Example</h3>
			<pre><strong>procedure</strong> TForm1.BtOpenClick(Sender: TObject);<br><strong>var</strong>
  Transaction: TUIBTransaction;
  Query1: TUIBQuery;
  Query2: TUIBQuery;
<strong>begin</strong>
  Transaction := TUIBTransaction.Create(<strong>nil</strong>);<br>  Query1 := TUIBQuery.Create(<strong>nil</strong>);<br>  Query2 := TUIBQuery.Create(<strong>nil</strong>);<br>  <strong>try</strong>
    Transaction.DataBase := DataBase;
    Query1.Transaction := Transaction;
    Query2.Transaction := Transaction;
    <strong>try</strong>
      Query1.SQL.Text := <font color="#333399">'SELECT * FROM MYTABLE1</font>;<br>      Query1.Open; <font color="#666699"><font color="#333399">// transaction </font><font color="#ff0066">started </font><font color="#333399">(Rule 1)</font>
</font>      <strong>while</strong> <strong>not</strong> Query1.Eof <strong>do</strong>
      <strong>begin</strong>
        <font color="#333399">// ...<br></font>        Query1.Next;<br>      <strong>end;</strong>
      Query1.Close; <font color="#333399">// <font color="#ff0066">Stay in</font> transaction (default action)</font>

      Query2.SQL.Text := <font color="#333399">'SELECT * FROM MYTABLE2'</font>;<br>      Query2.Open; <font color="#333399">// transaction not started because Query1 have not closed the Transaction.</font>
                   <font color="#333399">// On <font color="#ff0066">error</font> the transaction is automatically </font><font color="#ff0066">rollbacked</font><font color="#333399">(Rule 3)</font>
      
      <strong>while</strong> <strong>not</strong> Query1.Eof <strong>do</strong>
      <strong>begin</strong>
        <font color="#333399">// ...</font>
        Query2.Next;
      <strong>end</strong>;<br>      Query2.Close(etmCommit); <font color="#333399">// Transaction <font color="#ff0066">Commited</font> because Query1 is closed</font>
                               <font color="#333399">// if Query1 not closed and AutoRetain =    True, then <font color="#ff0066">CommitRetaining</font><font color="#333399">(Rule 2)</font>
</font>

    <strong>except</strong>
      Transaction.RollBack; <font color="#333399">// on <font color="#ff0066">error</font> transaction </font><font color="#ff0066">rollbacked</font>
      <font color="#333399">// ...</font>
       
    <strong>end</strong>;<br>  <strong>finally</strong>
    Query1.Free; <font color="#333399">// if transaction active then close &amp; </font><font color="#ff0066">commit</font><font color="#333399">(Rule 4)</font>
    Query2.Free; <font color="#333399">// if transaction active then close &amp; </font><font color="#ff0066">commit</font><font color="#333399">(Rule 4)</font>
    Transaction.Free;
  <strong>end</strong>;<br><strong>end;</strong>
</pre>
		</blockquote>
		<p>&nbsp;</p>
		<h2 align="left">Compiler Options</h2>
		<p align="left">First of all you have to set some compiler options depending which 
			type of application you are writing and which database you are using.<br>
			Edit the "UIB.inc" file in the source directory with a text editor and 
			uncomment compiler options you need.</p>
		<blockquote style="margin-right: 0px;" dir="ltr">
			<h3 align="left">Database.</h3>
			<blockquote>
				<h4 align="left">Borland Interbase</h4>
				<ul>
					<li>
						<div align="left">Interbase 6.0x, you don't need to set anything, you can work with 
							any database version.</div>
					</li><li>
						<div align="left">Interbase 6.5, <font color="#336600">{$DEFINE IB65}</font></div>
					</li><li>
						<div align="left">Interbase 7, <font color="#336600">{$DEFINE IB7}</font></div>
					</li>
				</ul>
				<h4 align="left">Filrebird</h4>
				<ul>
					<li>
						<div align="left">Firebird 1.02, <font color="#336600">{$DEFINE FB102}</font></div>
					</li><li>
						<div align="left">
							<div align="left">Firebird 1.03, <font color="#336600">{$DEFINE FB103}</font></div>
						</div>
					</li><li>
						<div align="left">
							<div align="left">Firebird 1.5,&nbsp;&nbsp; <font color="#336600">{$DEFINE FB15}</font></div>
						</div>
					</li><li>Firebird&nbsp;2, <font color="#336600">{$DEFINE FB20}</font></li>

				</ul></blockquote>
			<h3 align="left">Multithreading and N-Tiers servers&nbsp;application.</h3>
			<blockquote style="margin-right: 0px;" dir="ltr">
				<p align="left">You have&nbsp;2 choices:</p>
				<p align="left"><u>Sharing one DB connection with all threads</u>,&nbsp;in this 
					case 2 threads can share&nbsp;the same&nbsp;Database connection or&nbsp;the 
					same&nbsp;Transaction safely without freezing the server. Some examples of 
					server applications are: Web server, CORBA, DCOM, or Delphi ORB provided 
					provided with UIB. For an example of Multithread server try the the sample 
					applications in the "ClentServer" directory.&nbsp;You must set this compiler 
					option: <font color="#336600">{$DEFINE UIBTHREADSAFE}</font> excepting with 
					Interbase 7 (The library is allready ThreadSafe)</p>
			</blockquote><blockquote style="margin-right: 0px;" dir="ltr">
				<p><u>Create one DB Connection per Thread</u>, in this case you should desactivate <font color="#336600">
						{$DEFINE UIBTHREADSAFE}</font>, and setting your DB connection to use the 
					remote protocol (excepting with Interbase 7), to have all threads working 
					faster.</p>
			</blockquote>
			<h3>Borland C++ Builder 6</h3>
			<blockquote style="margin-right: 0px;" dir="ltr">
				<p>You can choose to use original Interbase header files (IBase.h &amp; IBError.h) 
					in this case uncomment <font color="#336600">{$DEFINE USE_IBERROR_H}</font> &amp;
					<font color="#336600">{$DEFINE USE_IBASE_H}</font>.</p>
			</blockquote>
			<h3 align="left">Languages
			</h3>
			<ul style="margin-right: 0px;" dir="ltr">
				<li>
					<div><font color="#336600">{$DEFINE UIBLANG_EN}</font>: English language. (Default)</div>
				</li><li>
					<div>
						<div><font color="#336600">{$DEFINE UIBLANG_DE}</font>:&nbsp;Deutch language.</div>
					</div>
				</li><li>
					<div><font color="#336600">{$DEFINE UIBLANG_FR}</font>: French&nbsp;language.&nbsp;</div>
				</li><li>
					<div>
						<div><font color="#336600">{$DEFINE UIBLANG_CZ}</font>:&nbsp;&nbsp;Czech 
							language.&nbsp;</div>
					</div>
				</li>
			</ul>
			<h3>Lazarus &amp; FPC</h3><p>&nbsp;</p>
		</blockquote>
	</body></html>